package edu.neusoft.yuejian_09.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import edu.neusoft.yuejian_09.R;
import edu.neusoft.yuejian_09.activity.ActInfoActivity;
import edu.neusoft.yuejian_09.activity.ClubDetailActivity;
import edu.neusoft.yuejian_09.bean.Club;
import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by Administrator on 2017/10/10.
 */

public class ClubListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{

    private Context mContext;
    private List mDataList;
    private LayoutInflater mLayoutInflater;

    public ClubListAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Club entity = (Club) mDataList.get(position);
        if (null == entity)
            return;
        //绑定数据
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.club_name.setText(entity.getClub_name());
        // System.out.printf("activity_name");
        String club_pic ="http://10.0.2.2/neu1_yuejian/Public/Admin/photo/"+entity.getClub_pic();

        Picasso.with(mContext).load(club_pic).into(viewHolder.club_pic);
        if(viewHolder.club_pic.getDrawable()==null){
            viewHolder.club_pic.setImageResource(R.drawable.no_pic);
        }
        //点击item跳转
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bundle bundle=new Bundle();
                bundle.putString("club_id",entity.getClub_id());
                bundle.putString("club_name",entity.getClub_name());
                bundle.putString("club_pic",entity.getClub_pic());
                bundle.putString("club_intro",entity.getClub_intro());
                bundle.putString("club_address",entity.getClub_address());
                //System.out.printf("club_address");
                bundle.putString("club_time",entity.getClub_time());
                bundle.putString("club_phone",entity.getClub_phone());

                //System.out.printf("club_time");
                Intent intent=new Intent(mContext, ClubDetailActivity.class);
                intent.putExtras(bundle);
                mContext.startActivity(intent);

            }
        });


    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        //创建ViewHolder
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_club, parent, false);
        return new ViewHolder(v);

    }

    //自定义的V
    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView club_pic;
        TextView club_name,club_intro;

        public ViewHolder(View itemView) {
            super(itemView);
            club_name = (TextView) itemView.findViewById(R.id.club_name);
            club_pic = (ImageView) itemView.findViewById(R.id.club_pic);
            club_intro= (TextView) itemView.findViewById(R.id.club_intro);

        }


    }
}

